//
//  ViewController.m
//  work
//
//  Created by Mac on 15/11/10.
//  Copyright © 2015年 zhihong. All rights reserved.
//

#import "ViewController.h"

#define VIEW_WIDTH (self.view.frame.size.width)
#define VIEW_HEIGHT (self.view.frame.size.height)

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT/3)];
    _myImage.image = [UIImage imageNamed:@"11.png"];
    [self.view addSubview:_myImage];
    
//    _myNumImage = [[UIImageView alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT/3, VIEW_WIDTH/8, VIEW_HEIGHT/9)];
//    _myNumImage.image = [UIImage imageNamed:@"55.png"];
//    [self.view addSubview:_myNumImage];
//    
//    _myPassImage = [[UIImageView alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT*4/9, VIEW_WIDTH/8, VIEW_HEIGHT/9)];
//    _myPassImage.image = [UIImage imageNamed:@"66.png"];
//    [self.view addSubview:_myPassImage];
    
//    _myNumText = [[UITextField alloc] initWithFrame:CGRectMake(VIEW_WIDTH/4, VIEW_HEIGHT/3, VIEW_WIDTH/2, VIEW_HEIGHT/9)];
    _myNumText = [[UITextField alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT/3, VIEW_WIDTH*3/4, VIEW_HEIGHT/9)];
    _myNumText.placeholder = @"请输入你的账号";
    _myNumText.textAlignment = NSTextAlignmentLeft;
    UIImageView * numImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"55.png"]];
    _myNumText.leftView = numImage;
    _myNumText.leftViewMode = UITextFieldViewModeAlways;
//    [_myNumText.leftView setFrame:CGRectMake(_myNumText.frame.origin.x/6, _myNumText.frame.origin.y, _myNumText.frame.size.height*2/3, _myNumText.frame.size.height*2/3)];
    _myNumText.delegate = self;
    _myNumText.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:_myNumText];
    
//    _myPassText = [[UITextField alloc] initWithFrame:CGRectMake(VIEW_WIDTH/4, VIEW_HEIGHT*4/9, VIEW_WIDTH/2, VIEW_HEIGHT/9)];
    _myPassText = [[UITextField alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT*4/9, VIEW_WIDTH*3/4, VIEW_HEIGHT/9)];
    _myPassText.placeholder = @"请输入你的密码";
    _myPassText.secureTextEntry = YES;
    _myPassText.textAlignment = NSTextAlignmentLeft;
    UIImageView * passImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"66.png"]];
    _myPassText.leftView = passImage;
    _myPassText.leftViewMode = UITextFieldViewModeAlways;
    _myPassText.delegate = self;
    _myPassText.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:_myPassText];
    
    _myLogbtn = [[UIButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT*11/19, VIEW_WIDTH*3/4, VIEW_HEIGHT/11)];
//    [_myLogbtn setTitle:@"登录" forState:UIControlStateNormal];
    [_myLogbtn setImage:[UIImage imageNamed:@"22.png"] forState:UIControlStateNormal];
//    _myLogbtn.backgroundColor = [UIColor greenColor];
    [_myLogbtn addTarget:self action:@selector(judge) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_myLogbtn];
    
    _myForgetbtn = [[UIButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH*3/4, VIEW_HEIGHT*2/3, VIEW_WIDTH/4, VIEW_HEIGHT/11)];
    [_myForgetbtn setTitle:@"忘记密码？" forState:UIControlStateNormal];
    [_myForgetbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:_myForgetbtn];
    
    _myQQLogbtn = [[UIButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH/8, VIEW_HEIGHT*3/4, VIEW_WIDTH*5/16, VIEW_HEIGHT/11)];
    [_myQQLogbtn setImage:[UIImage imageNamed:@"33.png"] forState:UIControlStateNormal];
    [self.view addSubview:_myQQLogbtn];
    
    _mySinaLogbtn = [[UIButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH*9/16, VIEW_HEIGHT*3/4, VIEW_WIDTH*5/16, VIEW_HEIGHT/11)];
    [_mySinaLogbtn setImage:[UIImage imageNamed:@"44.png"] forState:UIControlStateNormal];
    [self.view addSubview:_mySinaLogbtn];
    
}

- (void)judge {
    
    [self.view endEditing:YES];
    NSMutableString * str = [[NSMutableString alloc] init];
    if ([_myNumText.text length] == 0) {
        str = [NSMutableString stringWithFormat:@"请输入账号！"];
    } else if ([_myPassText.text length] == 0) {
        str = [NSMutableString stringWithFormat:@"请输入密码！"];
    } else {
        str = [NSMutableString stringWithFormat:@"登录成功！"];
    }
    
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:str message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:action];
    
    [self presentViewController:alert animated:YES completion:nil];
    //调试一下
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
